﻿namespace Dcms.Common
{
    using System;
    using System.Web.UI.WebControls;

    public class DcmsControl
    {
        public static void ClearText(TextBox[] list)
        {
            foreach (TextBox ctrl in list)
            {
                ctrl.Text = null;
            }
        }

        public static string GetDdlValue(DropDownList ctrl, int strType)
        {
            return ((strType == 0) ? ctrl.SelectedItem.Text : ctrl.SelectedValue);
        }

        public static string GetText(TextBox ctrl)
        {
            return ctrl.Text.Trim().Replace("'", "\"");
        }

        public static void time(DropDownList ctrl1, DropDownList ctrl2, DropDownList ctrl3)
        {
            ctrl3.Items.Clear();
            for (int i = 1; i < DateTime.DaysInMonth(Convert.ToInt32(ctrl1.SelectedValue), Convert.ToInt32(ctrl2.SelectedValue)) + 1; i++)
            {
                ctrl3.Items.Add(i.ToString());
            }
        }

        public static void time2(DropDownList[] list)
        {
            int i;
            int year = Convert.ToInt32(DateTime.Now.Year);
            int month = Convert.ToInt32(DateTime.Now.Month);
            int day = Convert.ToInt32(DateTime.Now.Day);
            int hour = Convert.ToInt32(DateTime.Now.Hour);
            int minute = Convert.ToInt32(DateTime.Now.Minute);
            for (i = year - 80; i < year + 1; i++)
            {
                list[0].Items.Add(i.ToString());
            }
            list[0].SelectedValue = "1980";
            for (i = 1; i < 13; i++)
            {
                list[1].Items.Add(i.ToString());
            }
            list[1].SelectedValue = month.ToString();
            for (i = 1; i < DateTime.DaysInMonth(year, month) + 1; i++)
            {
                list[2].Items.Add(i.ToString());
            }
            list[2].SelectedValue = day.ToString();
            switch (list.Length)
            {
                case 4:
                    for (i = 0; i < 0x18; i++)
                    {
                        list[3].Items.Add(i.ToString());
                    }
                    list[3].SelectedValue = hour.ToString();
                    break;

                case 5:
                    i = 0;
                    while (i < 0x18)
                    {
                        list[3].Items.Add(i.ToString());
                        i++;
                    }
                    list[3].SelectedValue = hour.ToString();
                    for (i = 0; i < 60; i++)
                    {
                        list[4].Items.Add(i.ToString());
                    }
                    list[4].SelectedValue = minute.ToString();
                    break;
            }
        }
    }
}

